﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ORS.Web
{
    public partial class ReviewSearch : System.Web.UI.Page
    {
        string s_key;
        DataTable dtsheet;
        ORS.BLL.SearchName rsearch = new ORS.BLL.SearchName();


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnquery_Click(object sender, EventArgs e)
        {
            string uid = HttpContext.Current.Session["reviewerid"].ToString();
            string reviewer = rsearch.getUsername(uid);
            if (rbtnqtype.SelectedValue == "0")
            {
                s_key = tbx_title.Text.Trim();
                dtsheet = rsearch.titleSearchReviewDataSet(s_key,reviewer);
            }
            else if (rbtnqtype.SelectedValue == "1")
            {
                s_key = tbx_author.Text.Trim();
                dtsheet = rsearch.userSearchReviewDataSet(s_key,reviewer);
            }
            else if (rbtnqtype.SelectedValue == "2")
            {
                s_key = DropDownList1.SelectedItem.Value.Trim();
                dtsheet = rsearch.interestSearchReviewDataSet(s_key,reviewer);
            }

            if (dtsheet.Rows.Count != 0)
            {
                btnreview.Visible = true;
                gvpaper2.DataSource = dtsheet;
                gvpaper2.DataBind();
            }
            else
            {
                btnreview.Visible = false;
                gvpaper2.DataSource = dtsheet;
                gvpaper2.DataBind();
            }
        }

        protected void gvpaper2_RowDateBoind(object sender,GridViewRowEventArgs e){
            if(e.Row.RowType == DataControlRowType.DataRow)
            {
                int rstate = int.Parse(((System.Data.DataRowView)e.Row.DataItem)["reviewstate"].ToString());
                int astate = int.Parse(((System.Data.DataRowView)e.Row.DataItem)["approvestate"].ToString());
                Label lblreviewstate = (Label)e.Row.FindControl("lblreviewstate");
                Label lblapprovestate = (Label)e.Row.FindControl("lblapprovestate");
                lblreviewstate.Text = RstateSearch(rstate);
                lblapprovestate.Text = AstateSearch(astate);
            }
        }

        protected string RstateSearch(int r_state)
        {
            ORS.BLL.SearchName robject = new ORS.BLL.SearchName();
            return robject.rStateSearch(r_state);

        }

        protected string AstateSearch(int a_state)
        {
            ORS.BLL.SearchName aobject = new ORS.BLL.SearchName();
            return aobject.rStateSearch(a_state);
        }

        protected void btnreview_Click(object sender, EventArgs e)
        {
            string[] paper_links = this.Request["paper_select"].Split(',');
            string link_url = paper_links[0].Trim();
            Response.Redirect(link_url);
        }

        protected void btnreset_Click(object sender, EventArgs e)
        {
            tbx_author.Text = "";
            tbx_title.Text = "";
        }
            
    }
}